package org.Game;

import android.graphics.Bitmap;
import android.graphics.Paint;
import android.graphics.Rect;

import com.example.gameex2.AppManager;
import com.example.gameex2.GraphicObject;
import com.example.gameex2.R;

public class JoyStick_Center extends GraphicObject {
	private JoyStick_Center m_JoyStickCenter;
	
	protected int m_radiusX = 17;
	protected int m_radiusY = 17;
	
	protected int m_CenterX = 49;
	protected int m_CenterY = 49;
	
	public int m_centralPointX = m_CenterX;
	public int m_centralPointY = m_CenterY;
	
	public boolean TouchMove = false;
	public Rect JoyStickRange = new Rect();
	
	
	public int m_r = 0;
	
	public JoyStick_Center(int getCenterX, int getCenterY) {
		// TODO Auto-generated constructor stub
		super(AppManager.getInstance().GetBitmap(R.drawable.center));
		// TODO Auto-generated constructor stub
		m_radiusX = GetCenterX();
		m_radiusY = GetCenterY();
		m_CenterX = getCenterX;
		m_CenterY = getCenterY;
		JoyStickRange.left = m_CenterX - m_radiusX;
		JoyStickRange.right = m_CenterX + m_radiusX;
		JoyStickRange.top = m_CenterY - m_radiusY;
		JoyStickRange.bottom = m_CenterY + m_radiusY;
		StartingPoint();
	}

	public void Update() {
	 if ( TouchMove )
	 this.SetPosition(m_centralPointX - m_radiusX, m_centralPointY - m_radiusY);
	}
	
	public void StartingPoint()
	{
		this.SetPosition(m_CenterX - m_radiusX , m_CenterY - m_radiusY);
	}
	
	public void PosLimit(float _x,float _y, int _limit)
	{
		m_centralPointX = (int)_x;
		m_centralPointY = (int)_y;
		
		Paint text1 = new Paint();
		
		Vector2 dir = new Vector2(m_centralPointX - m_CenterX, m_centralPointY - m_CenterY);
		dir.Normalize(dir);
		int r = (int)Math.sqrt( Math.pow(m_centralPointX - m_CenterX, 2 ) + Math.pow(  m_centralPointY - m_CenterY, 2 ) );
		m_r = r;
		if ( r > _limit)
		{
			m_centralPointX = (int) (dir.m_x*_limit) + m_CenterX;
			m_centralPointY = (int) (dir.m_y*_limit) + m_CenterY;
		}
	
	}
	
}
